*------------------------------------------------------------------------------------------------------------%	
* Figure 5: Average wage of $15 VMW companies, poaching and feeding firms, and unconnected firms
*------------------------------------------------------------------------------------------------------------%	
	
* 15 VMWs

* Load firm-level nonpolicy Credit Bureau data
use poaching_firm feeder_firm mdate trt_exp etime cz tot_emp avg_wage_exact tot_emp insample balanced_short if insample == 1 & balanced_short == 1 using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear

* Generate averages for groups of interest across all firms within CZ
	gen avg_wage_poach = avg_wage_exact if poaching_firm == 1
	gen avg_wage_feed = avg_wage_exact if feeder_firm == 1
	gen avg_wage_other = avg_wage_exact if feeder_firm != 1 & poaching_firm != 1
	
	gen tot_emp_poach = tot_emp if poaching_firm == 1
	gen tot_emp_feed = tot_emp if feeder_firm == 1
	gen tot_emp_other = tot_emp if feeder_firm != 1 & poaching_firm != 1
	
	collapse (rawsum) tot_emp tot_emp_feed tot_emp_poach tot_emp_other (mean) avg_wage_exact avg_wage_feed avg_wage_poach avg_wage_other [aw = tot_emp], by(mdate etime cz trt_exp)
	rename avg_wage_exact avg_wage_nonpol
	rename tot_emp tot_emp_nonpol
	
* Merge with policy Credit Bureau data
	preserve
		use mdate cz trt_exp avg_wage_exact tot_emp mw etime share_affected using "$data/cb/stacked_policy_firm_dataset.dta", clear
		rename avg_wage_exact avg_wage_policy
		rename tot_emp tot_emp_policy
		tempfile policy
		save `policy'
	restore
	merge m:1 mdate cz trt_exp using `policy', nogen

	gen year = yofd(dofm(mdate))

	drop if trt_exp==15 | trt_exp==16 | trt_exp==4
	
	keep if mw==15

* Generate weighted averages across all CZs
	foreach suf in "_poach" "_feed" "_other" "_nonpol" "_policy" {
		bysort etime : egen tot_tot_emp`suf' = sum(tot_emp`suf')
		gen wt_avg_wage`suf' = tot_emp`suf'*avg_wage`suf'/tot_tot_emp`suf'
		di "`suf'"
	}
	
	collapse (sum) wt_* mw, by(etime)

	rename wt_* *

* Graph

* Set as panel data
	tsset etime

* Label vars
	label variable avg_wage_nonpol "All nonpolicy"
	label variable avg_wage_poach "Poaching firms"
	label variable avg_wage_feed "Feeder firms"
	label variable avg_wage_other "Neither poach nor feed"
	label variable avg_wage_policy "Policy firm"
	label variable mw "Policy minimum wage"

	local mw=15
	local etime=etime

	graph tw ///
		(line avg_wage_other avg_wage_poach avg_wage_feed avg_wage_policy etime, lcolor("{$dnwbrown}" "${dnwblue}" "${dnwgold}" "${dnwcrimson}") lpattern(dot -. dash solid)), ///
		xline(0)  ///
		title("\$`mw' VMWs") ///
		ytitle("Average Wage (\$)") ///
		note("All in-sample nonpolicy firms. Nonpolicy firms balanced from -6 to +5.", size(vsmall)) ///
		legend(rows(2) pos(6) size(small))
	graph export "$figures_tables/fig6_average_wages_pol_nonpol_15.pdf", replace

*------------------------------------------------------------------------------------------------------------%	
* Figure D2: Average wage of Major VMW companies, poaching and feeding firms, and unconnected firms
*------------------------------------------------------------------------------------------------------------%	
	
* All VMWs
* Load firm-level nonpolicy Credit Bureau data
	use poaching_firm feeder_firm mdate trt_exp etime cz tot_emp avg_wage_exact tot_emp insample balanced_short if insample == 1 & balanced_short == 1 using "$data/cb/stacked_nonpolicy_firm_dataset_10pct.dta", clear

* Generate averages for groups of interest across all firms within CZ
	gen avg_wage_poach = avg_wage_exact if poaching_firm == 1
	gen avg_wage_feed = avg_wage_exact if feeder_firm == 1
	gen avg_wage_other = avg_wage_exact if feeder_firm != 1 & poaching_firm != 1
	
	gen tot_emp_poach = tot_emp if poaching_firm == 1
	gen tot_emp_feed = tot_emp if feeder_firm == 1
	gen tot_emp_other = tot_emp if feeder_firm != 1 & poaching_firm != 1
	
	collapse (rawsum) tot_emp tot_emp_feed tot_emp_poach tot_emp_other (mean) avg_wage_exact avg_wage_feed avg_wage_poach avg_wage_other [aw = tot_emp], by(mdate etime cz trt_exp)
	rename avg_wage_exact avg_wage_nonpol
	rename tot_emp tot_emp_nonpol
	
* Merge with policy Credit Bureau data
	preserve
		use mdate cz trt_exp avg_wage_exact tot_emp mw etime share_affected using "$data/cb/stacked_policy_firm_dataset.dta", clear
		rename avg_wage_exact avg_wage_policy
		rename tot_emp tot_emp_policy
		tempfile policy
		save `policy'
	restore
	merge m:1 mdate cz trt_exp using `policy', nogen

	gen year = yofd(dofm(mdate))
	drop if trt_exp==15 | trt_exp==16 | trt_exp==4

* Generate weighted averages across all CZs
	foreach suf in "_poach" "_feed" "_other" "_nonpol" "_policy" {
		bysort etime : egen tot_tot_emp`suf' = sum(tot_emp`suf')
		gen wt_avg_wage`suf' = tot_emp`suf'*avg_wage`suf'/tot_tot_emp`suf'
		di "`suf'"
	}
	

	collapse (sum) wt_* mw, by(etime)

	rename wt_* *

* Graph

* Set as panel data
	tsset etime

* Label vars
	label variable avg_wage_nonpol "All nonpolicy"
	label variable avg_wage_poach "Poaching firms"
	label variable avg_wage_feed "Feeder firms"
	label variable avg_wage_other "Neither poach nor feed"
	label variable avg_wage_policy "Policy firm"
	label variable mw "Policy minimum wage"

	local mw=15
	local etime=etime

	graph tw ///
		(line avg_wage_other avg_wage_poach avg_wage_feed avg_wage_policy etime, lcolor("{$dnwbrown}" "${dnwblue}" "${dnwgold}" "${dnwcrimson}") lpattern(dot -. dash solid)), ///
		xline(0)  ///
		title("All VMWs") ///
		ytitle("Average Wage (\$)") ///
		note("All in-sample nonpolicy firms. Nonpolicy firms balanced from -6 to +5.", size(vsmall)) ///
		legend(rows(2) pos(6) size(small))
	graph export "$figures_tables/appendix/figd2_average_wages_pol_nonpol_all.png", replace						

*------------------------------------------------------------------------------------------------------------%	
* Figure D3: Average wage of Major VMW companies, poaching and feeding firms, and unconnected firms
*------------------------------------------------------------------------------------------------------------%	
	
* Major VMWs
* Load firm-level nonpolicy Credit Bureau data
	use poaching_firm feeder_firm mdate trt_exp etime cz tot_emp avg_wage_exact tot_emp insample balanced_short if insample == 1 & balanced_short == 1 using "$data/cb/stacked_nonpolicy_firm_dataset_10pct.dta", clear

* Generate averages for groups of interest across all firms within CZ
	gen avg_wage_poach = avg_wage_exact if poaching_firm == 1
	gen avg_wage_feed = avg_wage_exact if feeder_firm == 1
	gen avg_wage_other = avg_wage_exact if feeder_firm != 1 & poaching_firm != 1
	
	gen tot_emp_poach = tot_emp if poaching_firm == 1
	gen tot_emp_feed = tot_emp if feeder_firm == 1
	gen tot_emp_other = tot_emp if feeder_firm != 1 & poaching_firm != 1
	
	collapse (rawsum) tot_emp tot_emp_feed tot_emp_poach tot_emp_other (mean) avg_wage_exact avg_wage_feed avg_wage_poach avg_wage_other [aw = tot_emp], by(mdate etime cz trt_exp)
	rename avg_wage_exact avg_wage_nonpol
	rename tot_emp tot_emp_nonpol
	
* Merge with policy Credit Bureau data
	preserve
		use mdate cz trt_exp avg_wage_exact tot_emp mw etime share_affected using "$data/cb/stacked_policy_firm_dataset.dta", clear
		rename avg_wage_exact avg_wage_policy
		rename tot_emp tot_emp_policy
		tempfile policy
		save `policy'
	restore
	merge m:1 mdate cz trt_exp using `policy', nogen

	gen year = yofd(dofm(mdate))

	drop if trt_exp==15 | trt_exp==16 | trt_exp==4
	keep if share_affected>.3

* Generate weighted averages across all CZs
	foreach suf in "_poach" "_feed" "_other" "_nonpol" "_policy" {
		bysort etime : egen tot_tot_emp`suf' = sum(tot_emp`suf')
		gen wt_avg_wage`suf' = tot_emp`suf'*avg_wage`suf'/tot_tot_emp`suf'
		di "`suf'"
	}
	

	collapse (sum) wt_* mw, by(etime)

	rename wt_* *

* Graph

* Set as panel data
	tsset etime

* Label vars
	label variable avg_wage_nonpol "All nonpolicy"
	label variable avg_wage_poach "Poaching firms"
	label variable avg_wage_feed "Feeder firms"
	label variable avg_wage_other "Neither poach nor feed"
	label variable avg_wage_policy "Policy firm"
	label variable mw "Policy minimum wage"

	local mw=15
	local etime=etime

	graph tw ///
		(line avg_wage_other avg_wage_poach avg_wage_feed avg_wage_policy etime, lcolor("{$dnwbrown}" "${dnwblue}" "${dnwgold}" "${dnwcrimson}") lpattern(dot -. dash solid)), ///
		xline(0)  ///
		title("Major VMWs") ///
		ytitle("Average Wage (\$)") ///
		note("All in-sample nonpolicy firms. Nonpolicy firms balanced from -6 to +5.", size(vsmall)) ///
		legend(rows(2) pos(6) size(small))
	graph export "$figures_tables/appendix/figd3_average_wages_pol_nonpol_major.png", replace

